<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="rgb(191, 203, 217)"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in data">
               
                <template v-if="item.subs">  <!--  判断有二级级-->
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i>
                            <span slot="title" class="nav_text pos1">{{ item.title }}</span>
                        </template>
                        <template  v-for="subItem in item.subs">
                                <template v-if="subItem.subs">   <!--  判断有3级级-->
                                            <el-submenu  v-if="subItem.subs" :index="subItem.index"  :key="subItem.index" >
                                                   
                                                    
                                                     <template slot="title">
                                                        
                                                            <span slot="title" class="nav_text pos2">{{ subItem.title }}</span>
                                                     </template>
                                                     
                                                       <template v-for="item4 in subItem.subs">
                                                            <template v-if="item4.subs">   <!--  判断有3级级-->
                                                                        <el-submenu  v-if="item4.subs" :index="item4.index"  :key="item4.index" >
                                                                            
                                                                                
                                                                                <template slot="title">
                                                                                        <i :class="item4.icon"></i>
                                                                                        <span slot="title" class="nav_text pos3">{{ item4.title }}</span>
                                                                                </template>
                                                                                 <el-menu-item
                                                                                    v-for="(fourItem,i) in item4.subs"
                                                                                    :key="i"
                                                                                    :index="fourItem.index"
                                                                                    class="nav_text pos4"
                                                                                    :title="fourItem.title"
                                                                                >{{ fourItem.title }}</el-menu-item>       
                                                                            
                                                                        </el-submenu>
                                                                        
                                                            </template>
                                                            <template v-else>
                                                                    <el-menu-item :index="item4.index" :key="item4.index">
                                                                        <i :class="item4.icon"></i>
                                                                        <span slot="title" class="nav_text">{{ item4.title }}</span>
                                                                    </el-menu-item>
                                                                </template>
                                                    </template>
                                                   
                                            </el-submenu>
                                            
                                 </template>
                                 <template v-else>
                                        <el-menu-item :index="subItem.index" :key="subItem.index">
                                            <i :class="subItem.icon"></i>
                                            <span slot="title" class="nav_text">{{ subItem.title }}</span>
                                        </el-menu-item>
                                    </template>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i>
                        <span slot="title"   class="nav_text">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>
 <!-- <el-menu-item
                                                        v-for="(threeItem,i) in subItem.subs"
                                                        :key="i"
                                                        :index="threeItem.index"
                                                        class="nav_text"
                                                    >{{ threeItem.title }}3</el-menu-item> -->
<script>
import bus from '../common/bus';
import arrySlide from '../../assets/js/sideData'
export default {
    data() {
        return {
            collapse: false,
            data: []
        };
    },
    computed: {
        onRoutes() {
         
            return this.$route.path.replace('/', '');
        }
    },
    created() {
  
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', msg => {
            this.collapse = msg;
           bus.$emit('collapse-content', msg);
        });
      this.getDep()
      

    },
    methods:{
        getDep(){
            let t=this;


            if(JSON.parse(localStorage.getItem('userinfo')).id==1){
                this.data=[{
                    icon: 'el-icon-lx-home',
                    index: 'textEditList',
                    title: '文本编辑',
                   },
                    {
                        icon: 'el-icon-lx-friend',
                        index: 'userList',
                        title: '用户列表',
                    }, {
                        icon: 'el-icon-lx-text',
                        index: 'logList',
                        title: '日志管理',
                    },
                ]
            }else{
                this.data=[{
                    icon: 'el-icon-lx-home',
                    index: 'textEditList',
                    title: '文本编辑',
                   }, {
                        icon: 'el-icon-lx-text',
                        index: 'logList',
                        title: '日志管理',
                    },
                ]
            }
            
           
        },
    }
};
</script>

<style scoped  lang="less">
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 200px;
}
.sidebar > ul {
    height: 100%;
    
}
.nav_text{
    font-size: 12px;
}
/deep/ .el-submenu__title{
    font-size: 12px;
 
}


/deep/ .pos4{
    padding-left: 65px !important;
}
</style>
